"""
文件名:WYJ_OrderInterface.py
作用: 订单管理 模块的接口,每一个接口都有一个对应的方法,该方法用于测试用例
作者: 吴宇杰
"""
from Untils.GetKeyword import GetKeyword
from Untils.SendMethod import SendMethod
from Interface.DHX_MemberInterface import MemberInterface
from Interface.YXL_UmsMemberReceiveAddressController import UmsMemberReceiveAddressControllerr


class OrderInterface:
    def __init__(self):
        self.orderId = 1
        self.url = 'http://139.159.146.104:8083'
        member = MemberInterface()
        self.headers = member.get_token(username='liar', password='123456')
        self.ra = UmsMemberReceiveAddressControllerr()

    def generate_confirm_order(self):
        """
        根据购物车信息生成确认单信息接口
        :return:
        """
        # 请求地址
        url = self.url + "/order/generateConfirmOrder"
        return SendMethod.send_method(method='post', url=url, headers=self.headers)

    def generate_order(self):
        """
        根据购物车信息生成订单接口
        :param orderParam:订单参数
        :return:
        """
        # 请求地址
        payload = {
            "memberReceiveAddressId": self.ra.get_id(),
            "payType": 1
        }
        url = self.url + "/order/generateOrder"
        # 请求数据
        order_result = SendMethod.send_method(method='post', url=url, json=payload, headers=self.headers)
        self.orderId = GetKeyword.get_keyword(order_result, 'orderId')
        return order_result

    def pay_success(self):
        """
        支付成功的回调接口
        :param orderId:订单id
        :return:
        """
        # 请求地址
        url = self.url + "/order/paySuccess"
        payload = {'orderId': self.orderId}
        print(self.orderId)
        # 请求数据
        return SendMethod.send_method(method='post', url=url, data=payload, headers=self.headers)


if __name__ == '__main__':
    order = OrderInterface()
    print(order.generate_confirm_order())
    print(order.generate_order())
    print(order.pay_success())
